package com.example.mallboot.controller;

import com.example.mallboot.common.api.CommonResult;
import com.example.mallboot.common.api.ResultCode;
import com.example.mallboot.dto.UmsMenuInfo;
import com.example.mallboot.service.UmsMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "admin",description = "后台管理")
@RestController
@RequestMapping("/admin")
public class UmsMenuController {
   @Resource
   private UmsMenuService umsMenuService;

    @ApiOperation(value = "获取列表查看")
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    @ResponseBody
    public CommonResult list(){
        List<UmsMenuInfo> info = umsMenuService.getUmsMenuAll();
        return CommonResult.success(info);
    }

    @ApiOperation("修改指定用户信息")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult  update(@RequestBody UmsMenuInfo info){
        boolean success = umsMenuService.updateById(info);
        if (success) {
            return CommonResult.success(null);
        }
        return CommonResult.failed();
    }

    @ApiOperation("删除指定用户信息")
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult delete(@PathVariable Integer id){
        boolean success = umsMenuService.removeById(id);
        if (success) {
            return CommonResult.success(null);
        }
        return CommonResult.failed();
    }


    @ApiOperation("注册用户信息add")
    @RequestMapping(value = "/register", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult register(@RequestBody UmsMenuInfo info){
        boolean success = umsMenuService.save(info);
        if (success) {
            return CommonResult.success(null);
        }
        return CommonResult.failed();
    }


}
